package gui;

import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;

import data.Chessozor;

public class MainFrame extends JFrame {
	private static final long serialVersionUID = 4743270606172960944L;
	private Chessozor game;
	private Skin skin;

	public MainFrame(Chessozor g) {
		super();

		this.game = g;
		try {
			this.skin = new Skin("img/");
		} catch (IOException e) {
			e.printStackTrace();
		}
		build();
	}

	private void build() {
		setTitle("Chessozor");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setContentPane(buildContentPane());
		pack();
		setLocationRelativeTo(null);
		setVisible(true);
	}

	private Container buildContentPane() {
		JPanel panel = new JPanel();

		panel.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints(0, 0,
				1, 1,
				1, 1,
				GridBagConstraints.CENTER, GridBagConstraints.NONE,
				new Insets(0, 0, 0, 0),
				0, 0);
		
		panel.add(new ChessboardPanel(this), c);
		
		c.gridx = 1;
		panel.add(new GamePanel(this), c);
		
		panel.setVisible(true);
		return panel;
	}

	public Chessozor getGame() {
		return game;
	}

	public Skin getSkin() {
		return skin;
	}

}
